package robotinterface.util;

import java.sql.*;
import java.util.*;

/**
 *
 * @author Bailey
 */
public class DBManager {

    private static Connection connection = null;

    public static Connection getConnection() {
        if (connection != null) { return connection; }
        else {
            try {
                ResourceBundle resource = ResourceBundle.getBundle("dbProperties");
                String DB_URL = resource.getString("db.url");
                String DB_USER = resource.getString("db.username");
                String DB_PASSWORD = resource.getString("db.password");
                String DB_DRIVER = resource.getString("db.driver");
                //System.out.printf("%s\n%s\n%s\n%s\n",DB_URL,DB_USER,DB_PASSWORD,DB_DRIVER);
                
                Class.forName(DB_DRIVER);
                connection = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);                
            } 
            catch (ClassNotFoundException | SQLException ex) { System.out.println( ex.getMessage() ); }
            return connection;
        }
    }  
}
